using Godot;
using System;

public partial class FinalCard : Sprite2D
{
	private const float LONG_PRESS_DURATION = 1.5f;
	private Sprite2D _bigSprite;
	private Label label;
	public bool penetrate=false ;
	private CollisionShape2D collisionShape;
	private Timer _longPressTimer;
	[Export]
	public int location { get; set; }
	[Export]
	public string id { get; set; }
	[Export]
	public string name { get; set; }
	[Export]
	public string attribute { get; set; }
	[Export]
	public int atk { get; set; }
	[Export]
	public int def { get; set; }
	[Export]
	public int grade { get; set; }
	[Export]
	public Vector2 placePosition { get; set; }
	public int attackTimes { get; set; }
	public int trueAtk;
	public int trueDef;
	public bool kjysTag = false;
	public bool kjysSumTag = false;
	public bool sexyMagic = false;
	public bool sixMagicTag = false;
	public bool mixMagic = false;
	public bool superGnsz = false;
	public bool superBtsz = false;
	public bool superFbsz = false;
	public override void _Ready()
	{
		 Name = id;
		 Texture = GD.Load<Texture2D>("res://photo/card/low/" + name + ".png");
		 GlobalPosition=placePosition;
		 label = new Label();
		 label.Text ="攻:"+atk+"\n守:"+def;
		 label.Position=new Vector2(-50,30);
		 label.AddThemeColorOverride("font_color", Colors.Green);
		 label.AddThemeFontSizeOverride("font_size", 26);
		 AddChild(label);
		
		 Area2D area = new Area2D();
		 collisionShape = new CollisionShape2D();
		 RectangleShape2D rectangleShape = new RectangleShape2D();
		 rectangleShape.Size = Texture.GetSize() * Scale ;
		 collisionShape.Shape = rectangleShape;
		 area.AddChild(collisionShape);
		
		 area.MouseEntered += OnBodyEntered;
		 area.MouseExited += OnBodyExited;

		 AddChild(area);
		
		 _longPressTimer = new Timer();
		 _longPressTimer.WaitTime = LONG_PRESS_DURATION;
		 _longPressTimer.OneShot = true;
		 _longPressTimer.Timeout += OnLongPressTimeout;
		 AddChild(_longPressTimer);
		
		 _bigSprite=GetParent().GetParent().GetNode<Sprite2D>("BigTemplate");
		
	}
	public void changeAD(int a, int d)
	{
		this.atk = a;
		this.def = d;
		label.Text = "攻:" + this.atk + "\n守:" + this.def ;
	}
	public void OnBodyEntered()
	{
		_longPressTimer.Start();
	}
	public void OnBodyExited()
	{
		_longPressTimer.Stop();
		_bigSprite.Visible = false;
	}
	
	private void OnLongPressTimeout()
	{
		_bigSprite.Texture = GD.Load<Texture2D>("res://photo/card/high/" + name + ".png");
		_bigSprite.Visible = true;
	}
}
